/*
 * @Author: wuqingchun
 * @Date: 2024-04-03 10:27:02
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-04-10 09:25:17
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <errno.h>
#include <unistd.h>

#include "file_stream.h"


void test_wbx()
{
    FILE* pstFile = fopen("test.txt", "wbx");
    if (pstFile == NULL)
    {
        printf("fopen(wbx) error, %s\n", strerror(errno));
    }
    else
    {
        fclose(pstFile);
    }

    pstFile = fopen("test.txt", "rx");
    if (pstFile == NULL)
    {
        printf("fopen(rx) error, %s\n", strerror(errno));
    }
    else
    {
        printf("fopen(rx) successfully\n");
        //fclose(pstFile);
    }
    
    pause();
}

int main(int argc, char **argv)
{   
    
    FileStream objFStream;

    int32_t iErr = objFStream.OpenFile("test.txt", "w+");
    if (iErr != 0)
    {
        return 0;
    }

    iErr = objFStream.SetFilePos(10);
    if (iErr != 0)
    {
        return 0;
    }

    long lPos = objFStream.GetFilePos();
    printf("Pos: %ld\n", lPos);

    iErr = objFStream.Write("Hello World", sizeof("Hello World") - 1);
    //iErr = objFStream.WriteByPos(0, "Hello World", sizeof("Hello World") - 1);
    if (iErr != 0)
    {
        return 0;
    }

    lPos = objFStream.GetFilePos();
    printf("Pos: %ld\n", lPos);

    return 0;
}